package com.zhb.cloud.utils;

import java.io.Serializable;
import java.util.Objects;

import lombok.Data;

/**
 * @ClassName: Result
 * @Description:返回结果处理
 * @author: zhb1316783262@163.com
 * @date: 2018年11月26日下午6:40:30
 */
@Data
public class ResultVo<T> implements Serializable {
	private static final long serialVersionUID = 1L;

	private int code;

	private String info;

	private T data;

	public boolean isSuccess() {
		return this.code == Result.SUCCESS.getCode();
	}

	public static <T> ResultVo<T> success(T data) {
		return new ResultVo<T>(data);
	}

	public static <T> ResultVo<T> error(Result result) {
		return new ResultVo<T>(result);
	}

	public ResultVo() {
		super();
	}

	private ResultVo(T data) {
		this.code = Result.SUCCESS.getCode();
		this.info = Result.SUCCESS.getInfo();
		this.data = data;
	}

	private ResultVo(Result result) {
		if (Objects.nonNull(result)) {
			this.code = result.getCode();
			this.info = result.getInfo();
		}
	}

	public ResultVo(int code, String info) {
		super();
		this.code = code;
		this.info = info;
	}

	public ResultVo(int code, String info, T data) {
		super();
		this.code = code;
		this.info = info;
		this.data = data;
	}
}
